<!--
 * @Author: 赵克强 huohuo625@163.com
 * @Date: 2024-04-23 16:44:00
 * @LastEditors: 赵克强 huohuo625@163.com
 * @LastEditTime: 2025-03-27 14:46:58
 * @FilePath: \hy-ui\src\views\forntIndex.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="forntIndex">
    <div class="top">
      <div class="topLeft">
        <div class="top_t">
          <img src="../assets/jijian/bannerLeft.png" alt="" />
          <div>
            <span>请时刻提高保密意识，增强保密观念，严格遵守保密纪律</span>
            <span>登录于：{{ loginDate }}</span>
          </div>
        </div>
        <div class="top_b">
          <el-button type="text" class="routeSetting" @click="handleOpenSetting"
            >设置</el-button
          >
          <div class="routeList">
            <div
              class="routeItem"
              v-for="(item, index) in selectedList"
              :key="index"
              @click="handleGoPage(item)"
            >
              <div
                class="iconCnt"
                :style="{ background: item.bgcolor || 'rgb(245, 34, 45)' }"
              >
                <svg-icon
                  :icon-class="item.icon || 'system'"
                  className="itemSvgClass"
                />
              </div>
              <span>{{ item.menuName }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="topRight">
        <div @click="() => $router.push('/work/own')">
          <div>
            <span>{{ countProcessList.countOwn }}</span>
            <span>我发起的</span>
          </div>
        </div>
        <div @click="() => $router.push('/work/todo')">
          <div>
            <span>{{ countProcessList.countTodo }}</span>
            <span>待办审批</span>
          </div>
        </div>
        <div @click="() => $router.push('/work/finished')">
          <div>
            <span>{{ countProcessList.countFinished }}</span>
            <span>已办审批</span>
          </div>
        </div>
        <div @click="() => $router.push('/work/copy')">
          <div>
            <span>{{ countProcessList.countCopy }}</span>
            <span>待阅审批</span>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom">
      <div class="bottom_l">
        <div
          class="bottom_left"
          :style="{ height: total > 4 ? '372px' : '322px' }"
        >
          <span class="bottom_left_title">我的待办</span>
          <div class="table">
            <el-table
              :data="tableData"
              stripe
              style="width: 100%"
              height="260px"
              size="small"
            >
              <el-table-column
                prop="procTitleName"
                label="标题"
                width="240"
                align="left"
                show-overflow-tooltip
              >
              </el-table-column>
              <el-table-column
                prop="startUserName"
                label="发起人"
                   align="left"
                   width="100"
              >
              </el-table-column>
              <el-table-column
                prop="startDeptName"
                label="发起单位"
                   align="left"
              >
              </el-table-column>
              <el-table-column prop="createTime" label="时间" align="left">
              </el-table-column>
              <el-table-column prop="taskName" label="当前状态" align="left">
              </el-table-column>
              <el-table-column fixed="right" label="操作" width="100">
                <template slot-scope="scope">
                  <el-button
                    @click="handleClick(scope.row)"
                    type="text"
                    size="small"
                    >办理</el-button
                  >
                </template>
              </el-table-column>
            </el-table>
            <div v-if="total > 4">
              <pagination
                v-show="total > 4"
                :total="total"
                :page.sync="pageNumProcess"
                :limit.sync="pageSizeProcess"
                @pagination="getListTodoProcess"
              />
            </div>
          </div>
        </div>
        <div
          class="bottom_left_flow"
          :style="{ height: total > 4 ? '150px' : '200px' }"
        >
          <span class="bottom_left_title">常用流程</span>
          <div
            class="process"
            :style="{ height: total > 4 ? '80px' : '140px' }"
          >
            <span
              v-for="item in processList"
              :key="item.deploymentId"
              @click="handleFormProcess(item)"
              >{{ item.processName }}</span
            >
          </div>
        </div>
      </div>
      <div class="bottom_right">
        <div class="bottom_right_t">
          <div class="noticeTitle">
            <span>公告通知</span>
            <i
              class="el-icon-more icon"
              @click="() => $router.push('/usercenter/notice')"
            ></i>
          </div>
          <div class="noticeList">
            <p
              v-for="item in noticeList"
              :key="item.noticeId"
              @click="handleMeaasgeDetail(item)"
            >
              {{ item.noticeTitle }}
            </p>
          </div>
        </div>
        <div class="bottom_right_b">
          <div class="testTask">
            <span>考试任务</span>
          </div>
          <div
            class="testTaskList"
            v-for="item in testList"
            :key="item.id"
            @click="handleTest(item)"
          >
            <p>{{ item.testPaperName }}</p>
          </div>
        </div>
      </div>
    </div>
    <el-dialog
      title="设置"
      :visible.sync="open"
      width="80%"
      :before-close="close"
    >
      <div class="main">
        <div class="left">
          <p class="titleApp">未配置常用菜单</p>
          <div class="appList">
            <draggable
              v-model="noSettingAppList"
              group="site"
              dragClass="dragClass"
              ghostClass="ghostClass"
              chosenClass="chosenClass"
              :style="style"
              :move="onMove1"
            >
              <transition-group :style="style">
                <div
                  class="routeItem"
                  v-for="(item) in noSettingAppList"
                  :key="item.menuId"
                >
                  <div
                    class="iconCnt"
                    :style="{ background: item.bgcolor || 'rgb(245, 34, 45)' }"
                  >
                    <svg-icon
                      :icon-class="item.icon || 'system'"
                      className="itemSvgClass"
                    />
                  </div>
                  <span>{{ item.menuName }}</span>
                </div>
              </transition-group>
            </draggable>
          </div>
        </div>
        <div class="right">
          <p class="titleApp">
            已配置常用菜单（<span style="color: red; font-size: 12px"
              >最多只可配置10个菜单</span
            >）
          </p>

          <div class="appList">
            <draggable
              v-model="settingAppList"
              group="site"
              dragClass="dragClass"
              ghostClass="ghostClass"
              chosenClass="chosenClass"
              :style="style"
              :move="onMove2"
            >
              <transition-group :style="style">
                <div
                  class="routeItem"
                  v-for="(item) in settingAppList"
                  :key="item.menuId"
                >
                  <div
                    class="iconCnt"
                    :style="{ background: item.bgcolor || 'rgb(245, 34, 45)' }"
                  >
                    <svg-icon
                      :icon-class="item.icon || 'system'"
                      className="itemSvgClass"
                    />
                  </div>
                  <span>{{ item.menuName }}</span>
                </div>
              </transition-group>
            </draggable>
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close" size="mini">取 消</el-button>
        <el-button type="primary" @click="handleSubmit" size="mini"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script >
import { listNotice } from "@/api/system/notice";
import { testTaskList } from "@/api/exam/testTask";
import {
  countProcess,
  getSettingApp,
  saveSettingApp,
  getNoSettingApp,
} from "@/api/system/home";
import { mapGetters } from "vuex";
import draggable from "vuedraggable";
import {
  listTodoProcess,
  listProcess,
  listClaimProcess,
} from "@/api/workflow/process";
export default {
  components: {
    draggable,
  },
  data() {
    return {
      noticeList: [],
      testList: [],
      TodoProcessList: [],
      processList: [],
      total: 0,
      pageNum: 1,
      pageSize: 10,
      pageNumProcess:1,
      pageSizeProcess:10,
      tableData: [],
      countProcessList: {},
      open: false,
      settingAppList: [],
      settingAppListCopy: [
        {
          menuId: "18518541515",
          menuName: "个人信息",
          icon: "user",
          bgcolor: "rgb(24, 144, 255)",
          path: "/usercenter/userinfo",
        },
        {
          menuId: "489415161115215",
          menuName: "通知公告",
          icon: "message",
          bgcolor: "rgb(250, 173, 20)",
          path: "/usercenter/notice",
        },
      ],
      noSettingAppList: [],
      style:
        "min-height:500px;display:flex;flex-wrap: wrap;width:100%;align-content:flex-start;align-items:flex-start",
    };
  },
  computed: {
    ...mapGetters(["sidebar", "avatar", "device"]),
    loginDate: {
      get() {
        return this.$store.state.user.loginInfo.loginDate;
      },
    },
    selectedList() {
      return this.settingAppList?.length
        ? this.settingAppList
        : this.settingAppListCopy;
    },
  },
  methods: {
    handleMeaasgeDetail(item) {
      this.$router.push({
        path: "/system/usercenter/index/" + item.noticeId,
      });
    },
    handleGoPage(row) {
      if (!row.component) {
        this.$router.push(row.path);
      } else {
        this.$router.push(`/${row.parentPath}/${row.path}`);
      }
    },
    onMove1(e, originalEvent) {
      if (this.settingAppList?.length >= 10) {
        if (document.getElementsByClassName("el-message").length == 0) {
          this.$message({
            message: "最多只可配置10个菜单",
            type: "error",
          });
        }
        return false;
      }
      return true;
    },
    onMove2(e, originalEvent) {
      if (this.settingAppList?.length <= 2) {
        if (document.getElementsByClassName("el-message").length == 0) {
          this.$message({
            message: "最少配置2个菜单",
            type: "error",
          });
        }
        return false;
      }
      return true;
    },
    handleFormProcess(row) {
      this.$router.push({
        path: "/workflow/process/start/" + row.deploymentId,
        query: {
          definitionId: row.definitionId,
        },
      });
    },
    handleTest(row) {
      this.$router.push({
        path: "/exam/testTask/exam",
        query: {
          taskId: row.taskId,
          testPaperId: row.testPaperId,
        },
      });
    },
    handleClick(row) {
      this.$router.push({
        path: "/workflow/process/detail/" + row.procInsId,
        query: {
          taskId: row.taskId,
          processed: true,
        },
      });
    },
    handleOpenSetting() {
      this.open = true;
    },
    close() {
    this.open = false;
      this.getSettingAppList()
      
    },
    async getCountProcess() {
      const res = await countProcess();
      if (res.code === 200) {
        this.countProcessList = res.data;
      }
    },
    async getNoticeList() {
      const res = await listNotice({ pageSize: 6, pageNum: 1 });
      if (res.code === 200) {
        this.noticeList = res.rows;
      }
    },
    async getTestTaskList() {
      const res = await testTaskList({
        pageSize: 6,
        pageNum: 1,
        status: 0,
        userFlag: 1,
      });
      if (res.code === 200) {
        this.testList = res.rows;
      }
    },
    async getListTodoProcess() {
      const res = await listTodoProcess({ pageSize: this.pageSizeProcess, pageNum: this.pageNumProcess });
      if (res.code === 200) {
        this.tableData = res.rows;
        this.total = res.total;
      }
    },
    async getProcessList() {
      const res = await listProcess({ pageSize: 999, pageNum: 1 });
      if (res.code === 200) {
        this.processList = res.rows;
      }
    },
    async handleSubmit(){
      if(!this.settingAppList?.length) {
        return this.$message.error('请配置常用应用！')
      }else{
        const arr = []
        this.settingAppList.forEach((item,index)=>{
          arr.push({menuId:item.menuId,sort:index})
        })
        const res = await saveSettingApp(arr)
        if(res.code === 200){
          this.$message.success('保存成功')
          this.close()
        }
      }
    },
    async getSettingAppList() {
      const res = await getSettingApp();
      const ids = [];
      if (res.code === 200 && res.data?.length) {
        this.settingAppList = res.data;
        if (this.settingAppList?.length) {
          this.settingAppList.forEach((item) => {
            ids.push(item.menuId);
          });
        }
      }
      const nores = await getNoSettingApp({
        menuType: "C",
        menuIds: ids.length ? ids.toString() : undefined,
      });
      if (nores.code === 200) {
        this.noSettingAppList = nores.data;
      }
    },
  },
  mounted() {
    this.getNoticeList();
    this.getTestTaskList();
    this.getListTodoProcess();
    this.getProcessList();
    this.getCountProcess();
    this.getSettingAppList();
  },
};
</script>
<style scoped lang="scss">
.forntIndex {
  width: 100%;
  min-height: 91.2vh;
  background: #f0f2f5;
  padding: 10px;
  .dragClass {
    background-color: #fff !important;
    opacity: 1 !important;
    box-shadow: none !important;
    outline: none !important;
    background-image: none !important;
  }
  .chosenClass {
    background-color: transparent !important;
    opacity: 1 !important;
  }
  .main {
    height: 60vh;
    border: 1px solid #e7e6e6;
    border-radius: 10px;
    display: flex;
    .left,
    .right {
      width: 50%;
      height: 100%;
      padding: 20px;
      .titleApp {
        margin: 0;
        font-size: 16px;
        color: #666;
        font-weight: bold;
      }
    }
    .left {
      border-right: 1px solid #e7e6e6;
    }
    .appList {
      // display: flex;
      // align-items: center;
      padding-top: 20px;
      flex-wrap: wrap;
      overflow-y: scroll;
      height: 100%;
      & > div {
        width: 100%;
        & > span {
          display: flex;
          align-items: center;
          flex-wrap: wrap;
        }
      }
      .routeItem {
        cursor: move;
        display: flex;
        flex-direction: column;
        margin-left: 40px;
        justify-content: center;
        align-items: center;
        margin-bottom: 20px;
        width: 12.5%;
        span {
          font-family: Microsoft YaHei;
          font-weight: 400;
          font-size: 14px;
          color: #333333;
          line-height: 14px;
          margin-top: 8px;
        }
        .iconCnt {
          width: 42px;
          height: 42px;
          display: flex;
          align-items: center;
          justify-content: center;
          background: #13d0bc;
          border-radius: 8px;

          .itemSvgClass {
            color: #fff;
            font-size: 24px;
          }
        }
      }
    }
  }
  .top {
    display: flex;
    .topLeft {
      width: calc(100% - 430px);
      .top_t {
        width: 100%;
        height: 125px;
        background: url(../assets/jijian/topBanner.png) no-repeat;
        background-size: cover;
        display: flex;
        align-items: center;
        padding: 28px 0 30px 34px;
        img {
          margin-right: 46px;
        }
        div {
          display: flex;
          flex-direction: column;
          & span:nth-of-type(1) {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 24px;
            color: #015ee5;
            margin-bottom: 23px;
            line-height: 24px;
          }
          & span:nth-of-type(2) {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 18px;
            color: #999999;
            line-height: 18px;
          }
        }
      }
      .top_b {
        height: 113px;
        width: 100%;
        background: #fff;
        position: relative;
        // box-shadow: 0px 4px 13px 0px rgba(11, 86, 197, 0.09);
        border-radius: 10px;
        margin-top: 10px;
        display: flex;
        align-items: center;
        .routeSetting {
          position: absolute;
          right: 10px;
          top: 0px;
        }
        .routeList {
          display: flex;
          align-items: center;
          .routeItem {
            display: flex;
            flex-direction: column;
            margin-left: 40px;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            span {
              font-family: Microsoft YaHei;
              font-weight: 400;
              font-size: 14px;
              color: #333333;
              line-height: 14px;
              margin-top: 8px;
            }
            .iconCnt {
              width: 42px;
              height: 42px;
              display: flex;
              align-items: center;
              justify-content: center;
              background: #13d0bc;
              border-radius: 8px;

              .itemSvgClass {
                color: #fff;
                font-size: 24px;
              }
            }
          }
        }
      }
    }
    .topRight {
      padding: 24px 21px 25px 22px;
      width: 429px;
      height: 249px;
      background: #ffffff;
      border-radius: 10px;
      margin-left: 10px;
      display: grid;
      grid-template-columns: 1fr 1fr;
      grid-template-rows: auto auto;
      grid-column-gap: 22px;
      grid-row-gap: 20px;
      justify-items: stretch;
      align-items: stretch;
      & > div {
        padding: 20px 0 0 22px;
        cursor: pointer;
        div {
          display: flex;
          flex-direction: column;
          & span:nth-of-type(1) {
            font-family: Microsoft YaHei;
            font-weight: bold;
            font-size: 26px;
            line-height: 26px;
            margin-bottom: 16px;
          }
          & span:nth-of-type(2) {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 14px;
            color: #333333;
            line-height: 14px;
          }
        }
      }
      & > div:nth-of-type(1) {
        background: url(../assets/jijian/rightTop1.png) no-repeat;
        & div span:nth-of-type(1) {
          color: #2c6cfd;
        }
      }
      & > div:nth-of-type(2) {
        background: url(../assets/jijian/rightTop2.png) no-repeat;
        & div span:nth-of-type(1) {
          color: #3fa4cf;
        }
      }
      & > div:nth-of-type(3) {
        background: url(../assets/jijian/rightTop3.png) no-repeat;
        & div span:nth-of-type(1) {
          color: #d99022;
        }
      }
      & > div:nth-of-type(4) {
        background: url(../assets/jijian/rightTop4.png) no-repeat;
        & div span:nth-of-type(1) {
          color: #13d0bc;
        }
      }
    }
  }
  .bottom {
    display: flex;
    margin-top: 10px;
    .bottom_l {
      width: calc(100% - 437px);
      margin-right: 10px;
    }
    .bottom_left_flow {
      width: 100%;
      height: 150px;
      margin-bottom: 20px;
      background: #ffffff;
      border-radius: 10px;
      margin-right: 10px;
      padding: 18px 20px 20px 20px;
      margin-bottom: 10px;
      .bottom_left_title {
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 16px;
        color: #000000;
        line-height: 16px;
      }
      .process {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr 1fr 1fr 1fr;
        grid-template-rows: auto auto;
        grid-column-gap: 20px;
        grid-row-gap: 10px;
        justify-items: stretch;
        align-items: stretch;
        margin-top: 20px;
        padding-left: 20px;
        height: 80px;
        overflow-y: scroll;
        span {
          display: inline-block;
          width: 100%;
          height: 20px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
          cursor: pointer;
          color: #2f54eb;
          font-size: 14px;
        }
      }
    }
    .bottom_left {
      width: 100%;
      height: 372px;
      margin-bottom: 20px;
      background: #ffffff;
      border-radius: 10px;
      margin-right: 10px;
      padding: 18px 20px 20px 20px;
      margin-bottom: 10px;
      .bottom_left_title {
        font-family: Microsoft YaHei;
        font-weight: 400;
        font-size: 16px;
        color: #000000;
        line-height: 16px;
      }
      .table {
        margin-top: 15px;
        ::v-deep .el-table__header th {
          background-color: #f2f7ff;
          font-family: Microsoft YaHei;
          font-weight: 400;
          font-size: 14px;
          color: #333333;
        }
      }
    }
    .bottom_right {
      .bottom_right_t {
        width: 429px;
        height: 260px;
        background: #ffffff;
        border-radius: 10px;
        padding: 13px 15px 24px 20px;
        .noticeTitle {
          display: flex;
          justify-content: space-between;
          margin-bottom: 8px;
          span {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 16px;
            color: #000000;
            line-height: 16px;
          }
          .icon {
            transform: rotate(90deg);
            color: #666;
            cursor: pointer;
          }
        }
        .noticeList {
          p {
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 14px;
            color: #666666;
            line-height: 16px;
            margin: 0;
            margin-top: 18px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            padding-left: 5px;
            cursor: pointer;
            &::before {
              content: "";
              display: inline-block;
              background: #cccccc;
              border-radius: 50%;
              width: 8px;
              height: 8px;
              left: 15px;
              margin-right: 8px;
            }
          }
          & p:nth-of-type(1)::before {
            background: #fe6643;
          }
        }
      }
      .bottom_right_b {
        margin-top: 10px;
        width: 429px;
        height: 262px;
        background: #ffffff;
        border-radius: 10px;
        padding: 13px 15px 24px 20px;
        .testTask {
          font-family: Microsoft YaHei;
          font-weight: 400;
          font-size: 16px;
          color: #000000;
          line-height: 16px;
          margin-bottom: 8px;
        }
        .testTaskList {
          p {
            padding-left: 5px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            font-size: 14px;
            color: #666666;
            line-height: 16px;
            margin: 0;
            margin-top: 18px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            cursor: pointer;
            &::before {
              content: "";
              display: inline-block;
              background: #cccccc;
              border-radius: 50%;
              width: 8px;
              height: 8px;
              left: 15px;
              margin-right: 8px;
            }
          }
          & p:nth-of-type(1)::before {
            background: #fe6643;
          }
        }
      }
    }
  }
}
</style>
